
import proj4 from 'proj4'
import { register } from "ol/proj/proj4";
import { transform } from "ol/proj";

const proj4Epsg = ((geom) => {
  var xy = []
  if (Math.floor(geom[0]).toString().length == 6) {
    proj4.defs("EPSG:4548", "+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs");
    register(proj4);
    return xy = transform(geom, "EPSG:4548", "EPSG:4326")
  } else {
    return xy = proj4('EPSG:3857', 'EPSG:4326', geom)
  }
})

export {
  proj4Epsg
}